package edu.com.wjt219971332.config;

import jakarta.servlet.*;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import java.io.IOException;

public class SpringIoCinit extends AbstractAnnotationConfigDispatcherServletInitializer {
    //root ioc容器的配置类
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{DataSourceJavaConfig.class, MapperJavaConflgNew.class, ServiceJavaConflg.class};
    }
    //web ioc容器的配置类指定
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{WebMvcJavaConflg.class};
    }
    //dispatcherServlet的拦截路径
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        return new Filter[]{filter};
    }
    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        //保存临时文件的目录，上传文件的最大容量，request的最大容量，临时文件的数量
        MultipartConfigElement config = new MultipartConfigElement("E:/test/fileupload");
        registration.setMultipartConfig(config);
    }
}
